Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SITCOM-1042: Add initial python code #1

Merged
merged 3 commits into from
Oct 26, 2023
Merged

SITCOM-1042: Add initial python code #1

merged 3 commits into from
Oct 26, 2023

Conversation

fred3m
Copy link
Collaborator

@fred3m fred3m commented Sep 22, 2023

No description provided.

@fred3m fred3m changed the title SITCOM-934: Add initial python code SITCOM-1042: Add initial python code Sep 22, 2023
@fred3m fred3m force-pushed the tickets/SITCOM-1042 branch from d7c241c to 6e537a0 Compare September 22, 2023 16:09
@fred3m fred3m force-pushed the tickets/SITCOM-1042 branch 2 times, most recently from 9a3513d to 0db1749 Compare October 10, 2023 19:25
@fred3m fred3m force-pushed the tickets/SITCOM-1042 branch from 17f0bc6 to 2464942 Compare October 10, 2023 19:34
python/lsst/rubintv/analysis/service/command.py Outdated Show resolved Hide resolved
python/lsst/rubintv/analysis/service/command.py Outdated Show resolved Hide resolved

def on_error(ws: WebSocketApp, error: str) -> None:
"""Error received from the server."""
print(f"\033[91mError: {error}\033[0m")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in mock_server.py there is a nicer way to show console colors (at least more redeable). Maybe we can add a printc function?

class Color(Enum):
RED = 0x33

printc(message, color)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I implemented this in a new rubinTV_analysis_service.utils module. I didn't do this before because the mock server (and even the print functions in the client module) aren't going to be used in production, they're just debugging tools as we develop the package, but I guess it doesn't hurt to include aprintc method.



# Registry of all commands
command_registry = {}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.- Move it as static attribute of the class BaseCommand
Or maybe:
.- add as static field on a new class where we can also add the execute_command (i.e. CommandHandler)

Another possibility is that it may be here on purpose....

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This had been intentional, but I like your method better. I didn't realize that I could attach a static variable to BaseCommand and just use the register class method to add commands to the same shared registry (but of course now that I think about it this behavior makes sense).

scripts/mock_server.py Outdated Show resolved Hide resolved
scripts/mock_server.py Outdated Show resolved Hide resolved
scripts/mock_server.py Outdated Show resolved Hide resolved

def __call__(self, table: sqlalchemy.Table) -> sqlalchemy.sql.elements.BooleanClauseList:
child_results = [child(table) for child in self.children]
try:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multiplex using a dictionary?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind converting this to match/case for readability, but using a dictionary lookup for 4 cases that won't ever change seems like overkill.

python/lsst/rubintv/analysis/service/query.py Outdated Show resolved Hide resolved
@fred3m fred3m merged commit ba59b35 into main Oct 26, 2023
5 checks passed
@fred3m fred3m deleted the tickets/SITCOM-1042 branch October 26, 2023 18:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants